home *** CD-ROM | disk | FTP | other *** search
- Path: news.sprintlink.net!datalytics!usenet
- From: Rob Stewart <stew@datalytics.com>
- Newsgroups: comp.lang.c++
- Subject: Re: A class with pointers to yet undeclared classes
- Date: Mon, 15 Apr 1996 13:09:32 -0400
- Organization: Datalytics, Inc
- Message-ID: <317282CC.5A18@datalytics.com>
- References: <4ksden$276@decaxp.HARVARD.EDU>
- NNTP-Posting-Host: 204.62.224.71
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0 (WinNT; I)
-
- Mark Mueller wrote:
- >
- > How do I convince the compiler that class B is going to be declared later?
- >
- > Mark
- > mueller@fas.harvard.edu
-
- A.h (or hpp, or hxx, etc.):
-
- class B;
-
- class A
- {
- B* m_pB;
- };
-
- A.cpp (or cxx, or C, or c++, etc.):
-
- #include <B.h>
- #include <A.h>
-
- .
- .
- .
-
- As you can see, you've told the compiler that B is a class, and
- so long as m_pB (in this case) is a pointer or reference to B,
- and you don't use it in any inline member functions, you're all
- set.
-
- This is a standard approach to reduce compilation times: by
- forward declaring classes, rather than including the class'
- header, you reduce the code that must be processed in the
- current translation unit.
-
- --
- Robert Stewart | My opinions are usually my own.
- Datalytics, Inc. | stew@datalytics.com
-